package com.haoxiaozi.www.GUIFunctionStudy;

import java.awt.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 34255
 * Date: 2024-12-07
 * Time: 16:05
 */
public class PanelDemo {
    public static void main(String[] args) {
        Frame frame = new Frame("Frame 1");

        //设置布局
        frame.setLayout(null);

        //创建面板
        Panel panel = new Panel();

        frame.setVisible(true);
        frame.setBounds(300,300,500,500);

        //设置面板相对窗口位置
        panel.setLocation(50,50);
        panel.setSize(400,400);

        //设置面板背景
        panel.setBackground(new Color(217, 189, 106));

        //添加面板组件
        frame.add(panel);

        //添加监听事件
        //设配器模式
        frame.addWindowListener(new WindowAdapter(){
            @Override
            public void windowClosing(WindowEvent e) {
                //结束程序
                System.exit(0);
            }
        });
    }
}
